<template>
    <view>
        <!-- 顶部内容 -->
        <view v-if="classinfo_user_data != null" class="top-content pr spacing-mb">  
            <!-- 内容 -->
            <view class="content padding-horizontal-main">
                <view class="head-base pr oh">
                    <!-- 左侧头像 -->
                    <view class="padding-bottom-xxl oh fl">
                        <view class="fl"><image @tap="preview_event" class="head-avatar circle bg-white va-m" :src="classinfo_user_data.user.avatar" mode="widthFix"></image></view>
                        <view class="fl">
							<view class="item-name cr-white va-m margin-left-lg">{{classinfo_user_data.user.nickname}}</view>
							<view class="item-name cr-white va-m margin-left-lg" v-if="classinfo_user_data.user.mobile_security != ''">{{classinfo_user_data.user.mobile_security}}</view>
						</view>
						<view class="cl"></view>
                    </view>
                </view>
			</view>
			<view class="shenfen pa">
				<text v-if="classinfo_user_data.have_company_info === 1">{{classinfo_user_data.user_shenfen}}</text>
				<text v-else style="color:#666;">未认证</text>
			</view>
		</view>
		<view v-if="classinfo_user_data != null" class="center-content bottom-line-exclude">
			<view class="content padding-horizontal-main">
				<!-- 用户中心公告 -->
				<view v-if="classinfo_user_data.txt_gonggao != ''" class="padding-bottom-main">
				    <uv-notice-bar :text="classinfo_user_data.txt_gonggao"></uv-notice-bar>
				</view>
				
				<!-- 魔方- - 插件 -->
				<block v-if="((plugins_fccprouniapp_mofang || null) != null) && classinfo_user_data.have_company_info === 1">
					<component-mofang :propData="plugins_fccprouniapp_mofang" propLocation="17"></component-mofang>
				</block>
				
				<view v-if="classinfo_user_data.have_company_info === 1 && classinfo_user_data.renwu_jindu.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size">{{classinfo_user_data.jindu_title}}</view>
					<view class="oh margin-top-sm">
						<block v-for="(item, index) in classinfo_user_data.renwu_jindu" :key="index">
							<view class="nav-item pr spacing-mb">
								<view class="fr">
									<text v-if="item.status == 0" class="t1">未完成</text>
									<text v-else class="t2">已完成</text>
								</view>
								<view class="item-name-dot pa"></view>
								<view class="item-name cr-base">{{item.desc}}</view>
							</view>
						</block>
					</view>
				</view>

				<!-- 聚合导航 -->
				<view v-if="classinfo_user_data.navigation_company.length > 0" class="nav-box padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size dis-none">管理中心</view>
					<view class="oh margin-top-sm">
						<block v-for="(item, index) in classinfo_user_data.navigation_company" :key="index">
							<view :data-value="item.event_value" :data-type="item.event_type" @tap="navigation_event" class="nav-item padding-main fl tc cp">
								<image :src="item.images_url" class="item-icon" mode="widthFix"></image>
								<view class="item-name single-text cr-base">{{item.name}}</view>
							</view>
						</block>
					</view>
				</view>

				<view v-if="classinfo_user_data.txt_zhengce.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size">经纪人政策</view>
					<view class="oh margin-top-sm">
						<block v-for="(item, index) in classinfo_user_data.txt_zhengce" :key="index">
							<view class="nav-item pr">
								<view class="item-name-dot pa"></view>
								<view class="item-name cr-base">{{item}}</view>
							</view>
						</block>
					</view>
				</view>
				<view v-if="classinfo_user_data.txt_fuwu.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size">线下服务</view>
					<view class="oh margin-top-sm">
						<block v-for="(item, index) in classinfo_user_data.txt_fuwu" :key="index">
							<view class="nav-item pr">
								<view class="item-name-dot pa"></view>
								<view class="item-name cr-base">{{item}}</view>
							</view>
						</block>
					</view>
				</view>
				<view v-if="classinfo_user_data.txt_youshi.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size">我们的优势</view>
					<view class="oh margin-top-sm">
						<block v-for="(item, index) in classinfo_user_data.txt_youshi" :key="index">
							<view class="nav-item pr">
								<view class="item-name-dot pa"></view>
								<view class="item-name cr-base">{{item}}</view>
							</view>
						</block>
					</view>
				</view>
				
				<view v-if="(classinfo_user_data.ketang || null) != null && classinfo_user_data.ketang.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="spacing-nav-title br-b">
						<text class="text-wrapper va-m text-size padding-left-main">{{classinfo_user_data.ketang_title}}</text>
						<text class="vice-name margin-left-lg cr-gray"></text>
						<navigator :url="'/pages/article-category/article-category?id='+classinfo_user_data.ketang_cat_id" hover-class="none" class="arrow-right padding-right-xxxl cr-gray fr">更多</navigator>
					</view>
					<view class="oh margin-top-sm">
						<view class="data-list padding-top-main oh">
							<view class="plugins-blog-list">
								<view v-for="(item, index) in classinfo_user_data.ketang" :key="index" class="item oh padding-main border-radius-main bg-white spacing-mb">
									<navigator :url="item.url" hover-class="none">
										<image class="blog-img fl radius" :src="item.images_url" mode="aspectFill"></image>
										<view class="base fr">
											<view class="single-text text-size">{{item.title}}</view>
											<view class="cr-grey margin-top-sm">{{item.article_category_name}}</view>
											<view v-if="(item.simple_desc || null) != null" class="cr-base text-size-sm multi-text margin-top-sm">{{item.simple_desc}}</view>
										</view>
									</navigator>
								</view>
							</view>
						</view>
					</view>
				</view>
				
				<!-- 魔方- - 插件 -->
				<block v-if="((plugins_fccprouniapp_mofang || null) != null) && classinfo_user_data.have_company_info === 0">
					<component-mofang :propData="plugins_fccprouniapp_mofang" propLocation="18"></component-mofang>
				</block>
				
				<view v-if="(classinfo_user_data.txt_contact || null) != null && classinfo_user_data.txt_contact.length > 0" class="txt-content padding-main border-radius-main bg-white spacing-mb pr">
					<view class="br-b padding-main item-title fw-b text-size">联系我们</view>
					<view class="oh margin-top-sm txt-contact pr">
						<image :src="classinfo_user_data.txt_contact.erweima" :data-img="classinfo_user_data.txt_contact.erweima" @tap="upload_show_event" class="item-icon pa" mode="widthFix"></image>
						<view v-if="(classinfo_user_data.txt_contact.weixin || null) != null" class="nav-item pr">
							<view class="item-name-tit pa">微信：</view>
							<view class="item-name cr-base">{{classinfo_user_data.txt_contact.weixin}}</view>
						</view>
						<view v-if="(classinfo_user_data.txt_contact.tel || null) != null" class="nav-item pr">
							<view class="item-name-tit pa">电话：</view>
							<view class="item-name cr-base">{{classinfo_user_data.txt_contact.tel}}</view>
						</view>
						<view v-if="(classinfo_user_data.txt_contact.email || null) != null" class="nav-item pr">
							<view class="item-name-tit pa">邮箱：</view>
							<view class="item-name cr-base">{{classinfo_user_data.txt_contact.email}}</view>
						</view>
					</view>
					<view class="oh margin-top-sm contact-box">
						<view v-if="(classinfo_user_data.txt_contact.tel || null) != null" class="fl">
							<view class="contact-box-tel tc" @tap="call_event" :data-value="classinfo_user_data.txt_contact.tel">
								<uni-icons type="phone" size="15" color="#36abff"></uni-icons>
								<view class="dis-inline-block">拨打电话</view>
							</view>
						</view>
						<view class="fr">
							<button @click="gotowork">
							    <uni-icons type="headphones" size="15" color="#36abff"></uni-icons>
							    <view class="dis-inline-block">联系客服</view>
							</button>
						</view>
						<view class="cl"></view>
					</view>
				</view>
            </view>
			
			<!-- 版权信息 -->
			<component-copyright></component-copyright>
        </view>
		<view v-else>
		    <!-- 提示信息 -->
		    <component-no-data :propMsg="data_list_loding_msg"></component-no-data>
		</view>
		<!-- #ifdef APP-PLUS -->
		<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" :permissionID="permissionID"></yk-authpup>
		<!-- #endif -->
        <!-- 底部tabBar -->
        <component-classinfo-footer :propBaseData="data_base"></component-classinfo-footer>
    </view>
</template>

<script>
    const app = getApp();
	// #ifdef APP-PLUS
	import ykAuthpup from "@/components/yk-authpup/yk-authpup";
	// #endif
	import componentNoData from '@/components/no-data/no-data';
    import componentCopyright from "@/components/copyright/copyright";
	import componentMofang from "@/components/mofang/mofang";
	import componentClassinfoFooter from '../public/footer';
	import {classinfo_base_info} from '@/pages/fcc/classinfo/public/common.js';

	var static_url_mini = app.globalData.get_static_url('mini');
    export default {
        data() {
            return {
				static_url_mini:static_url_mini,
                // 基础配置
                common_app_customer_service_tel: null,
                common_app_is_online_service: 0,
                // 滚动监听值
                scroll_value: 0,
                // 顶部导航信息
                top_nav_height: 50,
				// 主题信息
				plugins_fccprouniapp_data:null,
				// 魔方广告
				plugins_fccprouniapp_mofang:null,
				work_id:'',
				work_url:'',
				alldata:null,
				data_base:null,
				classinfo_user_data: null,
				permissionID: '',
				data_list_loding_msg: '',
            };
        },

        components: {
			// #ifdef APP-PLUS
			ykAuthpup,
			// #endif
			componentNoData,
            componentCopyright,
			componentMofang,
			componentClassinfoFooter
        },
        props: {},

        onShow() {
            // 数据加载
            this.init();
        },

        // 下拉刷新
        onPullDownRefresh(e) {
            this.init();
        },

        methods: {
			// 加载之前
			init() {
				// 先获取语言基础信息
				classinfo_base_info()
				.then(data=>{
					this.init_before(data)
					.then(()=>{
						this.init_real();
					});
				});
			},
			// 设置本页参数
			init_before(data){
				var self = this;
				return new Promise((resolve, reject) => {
					self.setData({
						data_base: data,
						common_app_customer_service_tel: app.globalData.get_config('config.common_app_customer_service_tel'),
						common_app_is_online_service: app.globalData.get_config('config.common_app_is_online_service'),
						//work_id:app.globalData.get_config('plugins_base.classinfo.data.kefu_id'),
						//work_url:app.globalData.get_config('plugins_base.classinfo.data.kefu_url'),
					});
					resolve();
				});
			},
			init_real() {
				var user = app.globalData.get_user_info(this, "init_real");
				if (user != false) {
					this.get_data();
					
					// 分享菜单处理
					app.globalData.page_share_handle();
				} else {
					uni.stopPullDownRefresh();
					this.data_list_loding_msg = '请先登录';
					// 分享菜单处理
					app.globalData.page_share_handle();
				}
			},
			
			// 上传图片预览
			upload_show_event(e) {
				var img = e.currentTarget.dataset.img;
			    var fapiao_img = [];
				fapiao_img.push(img);
			    uni.previewImage({
			        current: fapiao_img[0],
			        urls: fapiao_img
			    });
			},
			
			gotowork(){
				var self = this;
				console.log(self.work_url);
				console.log(self.work_id);
				wx.openCustomerServiceChat({
				  extInfo: {url: self.work_url},
				  corpId: self.work_id,
				  success(res) {
					  
				  }
				})
			},

            // 获取数据
            get_data() {
				return new Promise((resolve, reject) => {
					uni.request({
						url: app.globalData.get_request_url("center", "user"),
						method: "POST",
						data: {},
						dataType: "json",
						success: res => {console.log(res);
							uni.stopPullDownRefresh();
							if (res.data.code == 0) {
								var data = res.data.data.classinfo_user_data || null;
								var alldata = res.data.data || null;
								// 数据设置
								var upd_data = {
									alldata: alldata || null,
									plugins_fccprouniapp_data: alldata.plugins_fccprouniapp_data || null,
									classinfo_user_data: data,
								}
								
								if((alldata.plugins_fccprouniapp_data || null) != null)
								{
									upd_data['plugins_fccprouniapp_mofang'] = alldata.plugins_fccprouniapp_data.data || null;
								}
								this.setData(upd_data);
							} else {
								if (app.globalData.is_login_check(res.data, this, 'get_data')) {
									app.globalData.showToast(res.data.msg);
								}
							}
							
							// 分享菜单处理、延时执行，确保基础数据已加载完成
							setTimeout(function() {
								app.globalData.page_share_handle();
							}, 3000);
							
							resolve();
						},
						fail: () => {
							uni.stopPullDownRefresh();
							app.globalData.showToast("服务器请求出错");
							reject("服务器请求出错");
						}
					});
				});
            },

			// 客服电话
			call_event(e) {
			    var tel = e.currentTarget.dataset.value || null;
			    if (tel == null) {
			        app.globalData.showToast(this.$t('setup.setup.utnr7g'));
			    } else {
					if(app.globalData.is_android())
					{
						this.permissionID = 'CALL_PHONE';
						setTimeout(()=>{
							this.$refs['authpup'].open(tel);
						},500);
					}else{
						app.globalData.call_tel(tel);
					}
			    }
			},
			// #ifdef APP-PLUS
			//用户授权权限后的回调
			changeAuth(e){
				// 如果是头像查看的权限返回
				if(this.permissionID == 'WRITE_EXTERNAL_STORAGE')
				{
					// 直接下载
					app.globalData.save_image_by_url(e);
				}else{
					app.globalData.call_tel(e);
				}
			},
			// #endif

            // 头像查看
            preview_event() {
                if (app.globalData.data.default_user_head_src != this.classinfo_user_data.user.avatar) {
					if(app.globalData.is_android())
					{
						var self = this;
						uni.previewImage({
						    current: self.classinfo_user_data.user.avatar,
						    urls: [self.classinfo_user_data.user.avatar],
							longPressActions: {
								itemList: [self.$t('fengcheche.fcctips.t9')],
								success: function(data) {
									uni.closePreviewImage();
									self.permissionID = 'WRITE_EXTERNAL_STORAGE';
									setTimeout(()=>{
										self.$refs['authpup'].open(self.classinfo_user_data.user.avatar);
									},500);
								},
								fail: function(err) {
									console.log(err.errMsg);
								}
							}
						});
					}else{
						uni.previewImage({
						    current: this.classinfo_user_data.user.avatar,
						    urls: [this.classinfo_user_data.user.avatar]
						});
					}
                }
            },

            // 远程自定义导航事件
            navigation_event(e) {
                app.globalData.operation_event(e);
            }
        }
    };
</script>
<style>
    @import './company.css';
</style>